package com.learning.abstractdao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.RowMapper;

import com.laerning.abstractdao.LoginAbstractDao;
import com.learning.basedao.impl.BaseDaoImpl;
import com.learning.model.Users;

public class LoginAbstractDaoImpl extends BaseDaoImpl<Users, Integer> implements LoginAbstractDao {

	static final Logger log = LoggerFactory.getLogger(LoginAbstractDaoImpl.class);

    public static final boolean AUTO_INCREMENTED = false;

    public static final boolean SOFT_DELETED = false;

    public static final String TABLE_NAME = "Users";

    public static final String SCHEMA_NAME = "";

    protected String tableName()
    {
        return TABLE_NAME;
    }

    protected String schemaName()
    {
        return SCHEMA_NAME;
    }

private static final String[] attr = {
        "id",
        "username",
        "password",
        "role",
        
    };

    protected String[] attributes()
    {
        return attr;
    }

    protected RowMapper<Users> mapper()
    {
        return new RowMapper<Users>() {

            public Users mapRow(ResultSet rs, int rowNum) throws SQLException {
            Users item = new Users();
            	item.setId(rs.getInt("id"));
            	item.setUsername(rs.getString("username"));
            	item.setPassword(rs.getString("password"));
            	item.setRole(rs.getInt("role"));
                return item;
            }
        };
    }


    @Override
    protected Map<String, ?> mapValues(Users object) {
    Map<String,Object> valueMap = new GenericFactory<Object>().buildMap();
            valueMap.put("id",object.getId());
            valueMap.put("username",object.getUsername());
            valueMap.put("password",object.getPassword());
            valueMap.put("role",object.getRole());
           
            return valueMap;
    }

    @Override
    protected Class<Users> getEntityClass() {
        return Users.class;
    }


    private class GenericFactory<T> {

        public Map<String, T> buildMap() {
            return new HashMap<String, T>();
        }

    }

    public boolean isAutoIncremented() {
        return AUTO_INCREMENTED;
    }

    public boolean isSoftDeleted() {
        return SOFT_DELETED;
    }

}
